{% extends "index/main.html" -%}
{% block content -%}
{% set id = bo.id | default(value='') -%}
<form id="forms" action="{{ctx}}/users/saveUser.html" method="post" onsubmit="return iceui.validateForm('forms');">
    <input type="hidden" name="id" value="{{id}}">
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label required">姓名</label>
            <div class="group-content">
                <input type="text" name="name" rule="txt:姓名;required;length:20" value="{{bo.name | default(value='')}}"
                    placeholder="请输入姓名">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">编号</label>
            <div class="group-content">
                <input type="text" name="num" rule="txt:编号;length:10" value="{{bo.num | default(value='')}}">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label required">部门</label>
            <div class="group-content">
                <input type="hidden" id="department" name="department" value="{{bo.department | default(value='')}}">
                <select name="deptId" rule="txt:部门;required" change="changeDept" class="sel">
                    <option value=""></option>
                    {% for me in depts -%}
                        {% if me.id == bo.deptId | default(value='') -%}
                        <option value="{{me.id}}" selected>{{me.name}}</option>
                        {% else -%}
                        <option value="{{me.id}}">{{me.name}}</option>
                        {% endif -%}
                    {% endfor -%}
                </select>
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label required">职务</label>
            <div class="group-content">
                <select name="job" rule="txt:职务;required" class="sel">
                    <option value=""></option>
                    {% for me in jobs -%}
                        {% if me.name == bo.job | default(value='') -%}
                        <option value="{{me.name}}" selected>{{me.name}}</option>
                        {% else -%}
                        <option value="{{me.name}}">{{me.name}}</option>
                        {% endif -%}
                    {% endfor -%}
                </select>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">账号</label>
            <div class="group-content">
                <input type="text" id="username" name="username" rule="txt:账号;length:20"
                    value="{{bo.username | default(value='')}}" placeholder="用于登录系统时使用" onchange="validateUser()">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">密码</label>
            <div class="group-content">
                <input type="text" name="passwords" rule="txt:密码;length:20" value="{{bo.passwords | default(value='')}}"
                    placeholder="用于登录系统时使用">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label required">人员状态</label>
            <div class="group-content">
                <select name="statu" rule="txt:人员状态;required" class="sel">
                    <option value=""></option>
                    {% for val in status -%}
                        {% if val == bo.statu | default(value='') -%}
                        <option value="{{val}}" selected>{{val}}</option>
                        {% else -%}
                        <option value="{{val}}">{{val}}</option>
                        {% endif -%}
                    {% endfor -%}
                </select>
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">性别</label>
            <div class="group-content">
                {% set gender = bo.gender | default(value='') -%}
                {% if gender == "男" -%}
                <input type="radio" id="man" name="gender" value="男" checked class="radio">
                {% else -%}
                <input type="radio" id="man" name="gender" value="男" class="radio">
                {% endif -%}
                <label for="man" class="mr25">男</label>
                {% if gender == "女" -%}
                <input type="radio" id="woman" name="gender" value="女" checked class="radio">
                {% else -%}
                <input type="radio" id="woman" name="gender" value="女" class="radio">
                {% endif -%}
                <label for="woman" class="mr25">女</label>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label required">基础工资</label>
            <div class="group-content">
                <input type="text" name="basicWage" rule="txt:基础工资;required;double"
                    value="{{bo.basicWage | default(value='')}}" placeholder="请输入基础工资">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">保险金额</label>
            <div class="group-content">
                <input type="text" name="insurance" rule="txt:保险金额;double" value="{{bo.insurance | default(value='')}}">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w8 group-form">
            <label class="group-label">所属团队</label>
            <div class="group-content">
                <input type="text" name="team" rule="txt:所属团队;int" value="{{bo.team | default(value='')}}"
                    style="width: 48.8rem;">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">入职时间</label>
            <div class="group-content">
                <input type="text" id="hiredate" name="hiredate" value="{{bo.hiredate | default(value='')}}"
                    class="iceDate-icon">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">离职时间</label>
            <div class="group-content">
                <input type="text" id="leavedate" name="leavedate" value="{{bo.leavedate | default(value='')}}"
                    class="iceDate-icon">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">联系方式</label>
            <div class="group-content">
                <input type="text" name="telephone" value="{{bo.telephone | default(value='')}}">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">手机型号</label>
            <div class="group-content">
                <input type="text" name="brand" rule="txt:手机型号;length:20" value="{{bo.brand | default(value='')}}">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">身份证号</label>
            <div class="group-content">
                <input type="text" name="identity" rule="txt:身份证号;identity" value="{{bo.identity | default(value='')}}">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">出生年月</label>
            <div class="group-content">
                <input type="text" id="birthday" name="birthday" value="{{bo.birthday | default(value='')}}"
                    class="iceDate-icon">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">文化程度</label>
            <div class="group-content">
                <select name="education" class="sel">
                    <option value=""></option>
                    {% for val in educations -%}
                        {% if val == bo.education | default(value='') -%}
                        <option value="{{val}}" selected>{{val}}</option>
                        {% else -%}
                        <option value="{{val}}">{{val}}</option>
                        {% endif -%}
                    {% endfor -%}
                </select>
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">毕业时间</label>
            <div class="group-content">
                <input type="text" id="graduationDate" name="graduationDate"
                    value="{{bo.graduationDate | default(value='')}}" class="iceDate-icon">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w8 group-form">
            <label class="group-label">毕业院校</label>
            <div class="group-content">
                <input type="text" name="school" rule="txt:毕业院校;length:20" value="{{bo.school | default(value='')}}"
                    style="width: 48.8rem;">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w8 group-form">
            <label class="group-label">家庭住址</label>
            <div class="group-content">
                <input type="text" name="address" rule="txt:家庭住址;length:50" value="{{bo.address | default(value='')}}"
                    style="width: 48.8rem;">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">销售业绩</label>
            <div class="group-content">
                <input type="text">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">业绩排名</label>
            <div class="group-content">
                <input type="text">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w4 group-form">
            <label class="group-label">工资总额</label>
            <div class="group-content">
                <input type="text">
            </div>
        </div>
        <div class="w4 group-form">
            <label class="group-label">工资排名</label>
            <div class="group-content">
                <input type="text">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w8 group-form">
            <label class="group-label" style="padding-top: 6rem;">照片</label>
            <div class="group-content">
                <div style="float: left;">
                    {% if attach.path | default(value='') == '' %}
                    <img id="img" style="width: 10rem; height: 15rem;">
                    {% else %}
                    <img id="img" src="{{ctx}}/tmp/{{attach.path}}" style="width: 10rem; height: 15rem;">
                    {% endif %}
                </div>
                <div style="padding-left: 12rem; padding-top: 5.5rem;">
                    <input type="hidden" id="photoName" name="photoName" value="">
                    <input type="file" id="photo" onchange="changePhoto(this)" accept="image/jpeg" style="display: none;">
                    <a href="javascript:ice('#photo')[0].click();" class="btn btn-green">选择图片</a>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="w8 group-form">
            <button type="submit" class="btn bg-royal" style="margin-left: 25rem;">提交</button>
            <a href="{{ctx}}/users/userList.html" class="btn bg-royal">返回</a>
        </div>
    </div>
</form>
<div style="width: 62rem; text-align: right;">
    <button type="button" onclick="editUsersReward('');" class="btn bg-royal">添加奖惩记录</button>
</div>
<table id="tab" url="{{ctx}}/users/usersRewardList.html" pager="false" data="{'userId':'{{id}}'}"
    class="mt5 table table-border table-responsive table-hover" style="width: 62rem;">
    <thead>
        <tr>
            <th>序号</th>
            <th field="types">
                奖惩方式
            </th>
            <th field="reward">
                奖惩事件
            </th>
            <th field="rewardDate">
                奖惩时间
            </th>
            <th field="money">
                奖惩金额
            </th>
            <th render="opt">
                操作
            </th>
        </tr>
    </thead>
</table>
<script type="text/javascript">
    ice(function () {
        iceui.use('date', function () {
            ice.date({id: 'birthday', format: 'y-m-d'});
            ice.date({id: 'hiredate', format: 'y-m-d'});
            ice.date({id: 'leavedate', format: 'y-m-d'});
            ice.date({id: 'graduationDate', format: 'y-m-d'});
        });
        ice.use('popup');

        if ('{{id}}') {
            query('tab', 1);
        }
    });

    function validateUser() {
        var username = ice('#username').val();
        if (username == '') return;
        ice('button').attr('disabled', true);
        iceui.get('{{ctx}}/users/validateUser.html',
            {'id': '{{id}}', 'username': username},
            function (data) {
                if (data.code == '50') {
                    iceui.pop({title: '账号已被注册', icon: 'warning'});
                    return;
                }
                ice('button').delAttr('disabled');
            }
        );
    }
    
    function changeDept(val, text) {
        ice('#department').val(text);
    }
    
    function changePhoto(obj) {
        var file=obj.files[0];
        var reader=new FileReader();
        reader.readAsDataURL(file);
        reader.onload=function(e){
            var data=new FormData();
            data.append('file', file);
            iceui.post('{{ctx}}/uploadFile.html', data, function(data){
                if (data.code == '20') {
                    ice('#photoName').val(data.realname);
                }
            });
            ice('#img').attr('src', this.result);
        }
    }
    
    function opt(json) {
        return '<button type="button" onclick="editUsersReward('+json.id+')" class="btn bg-royal">编辑</button>';
    }

    function editUsersReward(id) {
        if (!'{{id}}') {
            iceui.pop({title: '请先保存职工信息', icon: 'warning'});
            return;
        }

        var src = '{{ctx}}/users/editUsersReward.html?userId={{id}}&id=' + id;
        ice.popup({
            src: src,
            title: '奖惩记录',
            width: 400,
            height: 500,
            color: 'blue',
            background: true
        });
    }
</script>
{% endblock content -%}